/*
 * TransaksiPenjualanForm.java
 *
 * Created on November 10, 2011, 8:57 PM
 */
package Transaksi;

import Login.Koneksi;
import Login.Login;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.Timer;

/**
 *
 * @author  Jo
 */
public class TransaksiPenjualanForm extends javax.swing.JPanel {

    /** Creates new form TransaksiPenjualanForm */
    int rowcount=0;
    public TransaksiPenjualanForm(Login login) {
        initComponents();
        buatnomor();
        GregorianCalendar gc = new GregorianCalendar();
        tanggalTransaksiJualChooser.setDate(gc.getTime());
        kasirTextField.setText(login.getLogin().getUserName());
        ActionListener taskPerformer = new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                jam2Label.setFont(new Font("jam", 1, 17));
                String nolJam = "";
                String nolMenit = "";
                String nolDetik = "";

                Date dt = new Date();

                int nilai_jam = dt.getHours();
                int nilai_menit = dt.getMinutes();
                int nilai_detik = dt.getSeconds();

                if (nilai_jam <= 9) {

                    nolJam = "0";
                }

                if (nilai_menit <= 9) {

                    nolMenit = "0";
                }

                if (nilai_detik <= 9) {

                    nolDetik = "0";
                }

                String jam = nolJam + Integer.toString(nilai_jam);
                String menit = nolMenit + Integer.toString(nilai_menit);
                String detik = nolDetik + Integer.toString(nilai_detik);
                // Menampilkan pada Layar
                jam2Label.setText("  " + jam + " : " + menit + " : " + detik + "  ");
            }
        };

        new Timer(1000, taskPerformer).start();


    }
     private void buatnomor() {
        try {
            Koneksi konek = new Koneksi();
            Statement statement = (Statement) konek.getConnection().createStatement();
            String sql = "select no_transaksi_beli from penjualan ORDER by no_transaksi_beli ";
            ResultSet rs = statement.executeQuery(sql);

            if (rs.next()) {
                int no_t = Integer.parseInt(rs.getString("no_transaksi_beli")) + 1;
                noTransaksiTextField.setText(Integer.toString(no_t));
            } else {
                int no_t = 1;
                noTransaksiTextField.setText(Integer.toString(no_t));
            }
            rs.close();
        } catch (Exception e) {
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        transaksiPenjualanDesktopPane = new javax.swing.JDesktopPane();
        panel1 = new javax.swing.JPanel();
        tanggalLabel = new javax.swing.JLabel();
        jamLabel = new javax.swing.JLabel();
        noTransaksiLabel = new javax.swing.JLabel();
        kasirLabel = new javax.swing.JLabel();
        noTransaksiTextField = new javax.swing.JTextField();
        kasirTextField = new javax.swing.JTextField();
        tanggalTransaksiJualChooser = new com.toedter.calendar.JDateChooser();
        judulLabel = new javax.swing.JLabel();
        jam2Label = new javax.swing.JLabel();
        panel2 = new javax.swing.JPanel();
        kodeBarangLabel = new javax.swing.JLabel();
        namaBarangLabel = new javax.swing.JLabel();
        hargaLabel = new javax.swing.JLabel();
        jumlahLabel = new javax.swing.JLabel();
        kodeBarangTextField = new javax.swing.JTextField();
        namaBarangTextField = new javax.swing.JTextField();
        hargaTextField = new javax.swing.JTextField();
        jumlahTextField = new javax.swing.JTextField();
        subtotalLabel = new javax.swing.JLabel();
        subtotalTextField = new javax.swing.JTextField();
        noUrutLabel = new javax.swing.JLabel();
        noUrutTextField = new javax.swing.JTextField();
        panel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        daftarBarangTabel = new javax.swing.JTable();
        panel4 = new javax.swing.JPanel();
        totaPembayaranLabel = new javax.swing.JLabel();
        bayarLabel = new javax.swing.JLabel();
        totalPenjualanTextField = new javax.swing.JTextField();
        bayarTextField = new javax.swing.JTextField();
        simpanButton = new javax.swing.JButton();
        hapusButton = new javax.swing.JButton();
        cetakButton = new javax.swing.JButton();
        batalButton = new javax.swing.JButton();
        kembaliTextField = new javax.swing.JTextField();
        kembaliLabel = new javax.swing.JLabel();
        totalPenjualanLabel = new javax.swing.JLabel();
        totalPembayaranTextField = new javax.swing.JTextField();

        panel1.setBackground(new java.awt.Color(0, 255, 204));

        tanggalLabel.setText("Tanggal");

        jamLabel.setText("Jam");

        noTransaksiLabel.setText("No Transaksi");

        kasirLabel.setText("Kasir");

        noTransaksiTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                noTransaksiTextFieldActionPerformed(evt);
            }
        });

        judulLabel.setFont(new java.awt.Font("Castellar", 1, 24));
        judulLabel.setText("Alfamaret");

        javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
        panel1.setLayout(panel1Layout);
        panel1Layout.setHorizontalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(238, 238, 238)
                        .addComponent(noTransaksiLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(judulLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(tanggalLabel)
                        .addGap(18, 18, 18)))
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tanggalTransaksiJualChooser, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(noTransaksiTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(kasirLabel)
                    .addComponent(jamLabel))
                .addGap(18, 18, 18)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jam2Label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(kasirTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
                .addGap(75, 75, 75))
        );
        panel1Layout.setVerticalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tanggalTransaksiJualChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(judulLabel)
                    .addComponent(tanggalLabel)
                    .addComponent(jamLabel)
                    .addComponent(jam2Label, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(kasirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(kasirLabel)
                    .addComponent(noTransaksiLabel)
                    .addComponent(noTransaksiTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        panel1.setBounds(0, 0, 680, 90);
        transaksiPenjualanDesktopPane.add(panel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        panel2.setBackground(new java.awt.Color(0, 255, 204));

        kodeBarangLabel.setText("Kode Barang");

        namaBarangLabel.setText("Nama Barang");

        hargaLabel.setText("Harga");

        jumlahLabel.setText("Jumlah");

        kodeBarangTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                kodeBarangTextFieldKeyReleased(evt);
            }
        });

        jumlahTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jumlahTextFieldKeyPressed(evt);
            }
        });

        subtotalLabel.setText("Subtotal");

        noUrutLabel.setText("No");

        javax.swing.GroupLayout panel2Layout = new javax.swing.GroupLayout(panel2);
        panel2.setLayout(panel2Layout);
        panel2Layout.setHorizontalGroup(
            panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(subtotalLabel)
                    .addComponent(jumlahLabel)
                    .addComponent(hargaLabel)
                    .addComponent(namaBarangLabel)
                    .addComponent(kodeBarangLabel)
                    .addComponent(noUrutLabel))
                .addGap(58, 58, 58)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(noUrutTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                    .addComponent(kodeBarangTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                    .addComponent(hargaTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                    .addComponent(jumlahTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                    .addComponent(subtotalTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                    .addComponent(namaBarangTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE))
                .addGap(370, 370, 370))
        );
        panel2Layout.setVerticalGroup(
            panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel2Layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(noUrutLabel)
                    .addComponent(noUrutTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(kodeBarangLabel)
                    .addComponent(kodeBarangTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(namaBarangLabel)
                    .addComponent(namaBarangTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(hargaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(hargaLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jumlahTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jumlahLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(subtotalLabel)
                    .addComponent(subtotalTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        panel2.setBounds(0, 90, 680, 190);
        transaksiPenjualanDesktopPane.add(panel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        panel3.setBackground(new java.awt.Color(0, 255, 204));

        daftarBarangTabel.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "No", "Kode Barang", "Nama Barang", "Harga", "Jumlah", "Sub Total"
            }
        ));
        jScrollPane1.setViewportView(daftarBarangTabel);

        javax.swing.GroupLayout panel3Layout = new javax.swing.GroupLayout(panel3);
        panel3.setLayout(panel3Layout);
        panel3Layout.setHorizontalGroup(
            panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 660, Short.MAX_VALUE)
                .addContainerGap())
        );
        panel3Layout.setVerticalGroup(
            panel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel3Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        panel3.setBounds(0, 280, 680, 130);
        transaksiPenjualanDesktopPane.add(panel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        panel4.setBackground(new java.awt.Color(0, 255, 204));

        totaPembayaranLabel.setText("Total Pembayaran");

        bayarLabel.setText("Bayar");

        totalPenjualanTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                totalPenjualanTextFieldKeyPressed(evt);
            }
        });

        bayarTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                bayarTextFieldKeyPressed(evt);
            }
        });

        simpanButton.setText("Simpan");
        simpanButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                simpanButtonActionPerformed(evt);
            }
        });

        hapusButton.setText("Hapus");

        cetakButton.setText("Cetak");

        batalButton.setText("Batal");
        batalButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                batalButtonActionPerformed(evt);
            }
        });

        kembaliLabel.setText("Kembali");

        totalPenjualanLabel.setText("Total Penjualan");

        javax.swing.GroupLayout panel4Layout = new javax.swing.GroupLayout(panel4);
        panel4.setLayout(panel4Layout);
        panel4Layout.setHorizontalGroup(
            panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(simpanButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hapusButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(batalButton)
                .addGroup(panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel4Layout.createSequentialGroup()
                        .addGap(179, 179, 179)
                        .addGroup(panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(panel4Layout.createSequentialGroup()
                                .addGroup(panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(bayarLabel)
                                    .addComponent(totalPenjualanLabel)
                                    .addComponent(kembaliLabel))
                                .addGap(21, 21, 21))
                            .addGroup(panel4Layout.createSequentialGroup()
                                .addComponent(totaPembayaranLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                        .addGroup(panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(totalPenjualanTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                            .addComponent(totalPembayaranTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                            .addComponent(bayarTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                            .addComponent(kembaliTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)))
                    .addGroup(panel4Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cetakButton)))
                .addContainerGap())
        );
        panel4Layout.setVerticalGroup(
            panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panel4Layout.createSequentialGroup()
                        .addGroup(panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(simpanButton)
                            .addComponent(hapusButton)
                            .addComponent(batalButton)
                            .addComponent(cetakButton))
                        .addGap(22, 22, 22))
                    .addGroup(panel4Layout.createSequentialGroup()
                        .addGroup(panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(totalPenjualanLabel)
                            .addComponent(totalPenjualanTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(totalPembayaranTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(totaPembayaranLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bayarTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bayarLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(kembaliTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(kembaliLabel))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        panel4.setBounds(0, 410, 680, 140);
        transaksiPenjualanDesktopPane.add(panel4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(transaksiPenjualanDesktopPane, javax.swing.GroupLayout.PREFERRED_SIZE, 680, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(transaksiPenjualanDesktopPane, javax.swing.GroupLayout.PREFERRED_SIZE, 547, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void noTransaksiTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noTransaksiTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_noTransaksiTextFieldActionPerformed

    private void simpanButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simpanButtonActionPerformed
        // TODO add your handling code here:
            for (int i = 0; i < daftarBarangTabel.getRowCount(); i++) {
                  Transaksi transaksi = new Transaksi();
                    String nonota = noTransaksiTextField.getText();
                    
//                    String kode = detailBarangTabel.getValueAt(i, 1).toString();
//                    String nama = detailBarangTabel.getValueAt(i, 2).toString();
//                    int harga = Integer.parseInt(detailBarangTabel.getValueAt(i, 3).toString());
//                    int jumlah = Integer.parseInt(detailBarangTabel.getValueAt(i, 4).toString());
//                    int diskon = Integer.parseInt(detailBarangTabel.getValueAt(i, 5).toString());
//                    int totalharga = Integer.parseInt(detailBarangTabel.getValueAt(i, 6).toString());
//                    ritel.setNoRitel(nonota);
//                    ritel.setUrut(urut);
//                    ritel.setKodeBarang(kode);
//                    ritel.setNamaBarang(nama);
//                    ritel.setHargasatuan(harga);
//                    ritel.setJumlah(jumlah);
//                    ritel.setDiskon(diskon);
//                    ritel.setTotal(totalharga);
//                    penjualanRitelKontroller.getBarangKoneksi().simpanRitelPermanent(ritel);
                }
    }//GEN-LAST:event_simpanButtonActionPerformed

    private void batalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_batalButtonActionPerformed
        // TODO add your handling code here:\
        kodeBarangTextField.setText("");
        namaBarangTextField.setText("");
        hargaTextField.setText("");
        jumlahTextField.setText("");
        
    }//GEN-LAST:event_batalButtonActionPerformed

    private void kodeBarangTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_kodeBarangTextFieldKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_kodeBarangTextFieldKeyReleased

    private void totalPenjualanTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_totalPenjualanTextFieldKeyPressed
        // TODO add your handling code here:
            if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                Double totalPenjualan = Double.parseDouble(totalPenjualanTextField.getText());
                Double totalPembayaran = (totalPenjualan*0.1)+totalPenjualan;
                totalPembayaranTextField.setText(String.valueOf(totalPembayaran));
        }

    }//GEN-LAST:event_totalPenjualanTextFieldKeyPressed

    private void bayarTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_bayarTextFieldKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        Double totalPembayaran = Double.parseDouble(totalPembayaranTextField.getText());
        Double jumlahBayar = Double.parseDouble(bayarTextField.getText());

       double kembali = jumlahBayar-totalPembayaran;
       kembaliTextField.setText(String.valueOf(kembali));
        }
    }//GEN-LAST:event_bayarTextFieldKeyPressed

    private void jumlahTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jumlahTextFieldKeyPressed
        // TODO add your handling code here:
         if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            int row = daftarBarangTabel.getSelectedRow();
            int urut=0;
            double sum=0;

            Double harga = Double.parseDouble(hargaTextField.getText());
            Double jumlah = Double.parseDouble(jumlahTextField.getText());
            Double subtotal=harga*jumlah;
            subtotalTextField.setText(String.valueOf(subtotal));


            daftarBarangTabel.setValueAt(noUrutTextField.getText(), rowcount, 0);
            daftarBarangTabel.setValueAt(kodeBarangTextField.getText(), rowcount, 1);
            daftarBarangTabel.setValueAt(namaBarangTextField.getText(), rowcount, 2);
            daftarBarangTabel.setValueAt(hargaTextField.getText(), rowcount, 3);
            daftarBarangTabel.setValueAt(jumlahTextField.getText(), rowcount, 4);
            daftarBarangTabel.setValueAt(subtotalTextField.getText(), rowcount, 5);


           rowcount++;
           sum=sum+subtotal;
           totalPenjualanTextField.setText(String.valueOf(sum));
           noUrutTextField.setText("" + (rowcount + 1));
       
        }

    }//GEN-LAST:event_jumlahTextFieldKeyPressed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton batalButton;
    private javax.swing.JLabel bayarLabel;
    private javax.swing.JTextField bayarTextField;
    private javax.swing.JButton cetakButton;
    private javax.swing.JTable daftarBarangTabel;
    private javax.swing.JButton hapusButton;
    private javax.swing.JLabel hargaLabel;
    private javax.swing.JTextField hargaTextField;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel jam2Label;
    private javax.swing.JLabel jamLabel;
    private javax.swing.JLabel judulLabel;
    private javax.swing.JLabel jumlahLabel;
    private javax.swing.JTextField jumlahTextField;
    private javax.swing.JLabel kasirLabel;
    private javax.swing.JTextField kasirTextField;
    private javax.swing.JLabel kembaliLabel;
    private javax.swing.JTextField kembaliTextField;
    private javax.swing.JLabel kodeBarangLabel;
    private javax.swing.JTextField kodeBarangTextField;
    private javax.swing.JLabel namaBarangLabel;
    private javax.swing.JTextField namaBarangTextField;
    private javax.swing.JLabel noTransaksiLabel;
    private javax.swing.JTextField noTransaksiTextField;
    private javax.swing.JLabel noUrutLabel;
    private javax.swing.JTextField noUrutTextField;
    private javax.swing.JPanel panel1;
    private javax.swing.JPanel panel2;
    private javax.swing.JPanel panel3;
    private javax.swing.JPanel panel4;
    private javax.swing.JButton simpanButton;
    private javax.swing.JLabel subtotalLabel;
    private javax.swing.JTextField subtotalTextField;
    private javax.swing.JLabel tanggalLabel;
    private com.toedter.calendar.JDateChooser tanggalTransaksiJualChooser;
    private javax.swing.JLabel totaPembayaranLabel;
    private javax.swing.JTextField totalPembayaranTextField;
    private javax.swing.JLabel totalPenjualanLabel;
    private javax.swing.JTextField totalPenjualanTextField;
    private javax.swing.JDesktopPane transaksiPenjualanDesktopPane;
    // End of variables declaration//GEN-END:variables
}
